﻿using System.Diagnostics;

public class MethodContext
{
    private readonly Stack<LuaAstTree> _stack = new Stack<LuaAstTree>();
    public void Push(params LuaAstTree[] trees)
    {
        foreach (var tree in trees)
            _stack.Push(tree);
    }
    public int Count => _stack.Count;
    public LuaAstTree Pop()
    {
        Debug.Assert(Count > 0);
        return _stack.Pop();
    }
    public LuaAstTree[] Pop(int len)
    {
        Debug.Assert(Count >= len);
        var trees = new LuaAstTree[len];
        for (int i = len - 1; i >= 0; i--)
            trees[i] = _stack.Pop();
        return trees;
    }
    public LuaAstTree StackTop
    {
        get
        {
            Debug.Assert(Count > 0);
            return _stack.Peek();
        }
    }

}

